package com.cw.jeeyt.service.bo.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import lombok.Data;

/**
 * 用户信息实体类
 *
 * @author chenw
 * @version 1.0.0
 */
@Data
public class SecurityUserBo implements Serializable, UserDetails {
    private static final long serialVersionUID = 1L;
    /** 主键id */
    @JsonSerialize(using= ToStringSerializer.class)
    private Long id;
    /** 账号 */
    private String account;
    /** 用户名称 */
    private String username;
    /** 密码 */
    private String password;
    /** 账号是否过期 */
    private Boolean accountNonExpired;
    /** 账号是否被锁 */
    private Boolean accountNonLocked;
    /** 凭证是否过期 */
    private Boolean credentialsNonExpired;
    /** 账号是否可用 */
    private Boolean enabled;
    /** 状态 */
    private String status;
    /** 性别 */
    private String sex;
    /** 类型 */
    private String type;
    /** 职位 */
    private String position;
    /** 手机号 */
    private String mobile;
    /** 办公电话 */
    private String telephone;
    /** 邮箱 */
    private String email;
    /** 扩展属性 */
    private String extend;
    /** 默认机构ID */
    private Long defaultOrgId;
    /** 用户状态 */
    private Boolean userState;
    /** 状态中文名 */
    private String statusCn;
    /** 说明 */
    private String comment;
    /** 创建人 */
    @JsonSerialize(using= ToStringSerializer.class)
    private Long createBy;
    /** 创建时间 */
    private java.util.Date createDate;
    @JsonSerialize(using= ToStringSerializer.class)
    /** 修改人 */
    private Long updateBy;
    /** 修改时间 */
    private java.util.Date updateDate;
    /** 用户角色 */
    private Set<SecurityUserRoleBo> userRoles = new HashSet<>();
    /** 角色 */
    private List<SecurityRoleBo> roles = new ArrayList<>();
    /** 扩展集合 */
    /** 角色id集合 */
    private String roleIds;
    /** 角色名称集合 */
    private String roleNames;
    /** 新密码 */
    private String newPassword;
    /** 重复输入新密码 */
    private String reNewPassword;
    /** 确认密码 */
    private String rePassword;

    /** default constructor */
    public SecurityUserBo() {
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {

        return AuthorityUtils.commaSeparatedStringToAuthorityList(roleNames);
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
